package com.game.modular.game.playerInfo.service;

import com.game.modular.game.playerInfo.service.base.PlayerRankBaseServiceImpl;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import com.game.modular.game.playerInfo.domain.PlayerRank;
import org.springframework.stereotype.Service;

/**
 * 玩家信息(PlayerRank)表服务实现类
 *
 * @author cxy
 * @since 2024-09-09 18:30:36
 */
@Slf4j
@Service
@RequiredArgsConstructor
public class PlayerRankServiceImpl extends PlayerRankBaseServiceImpl {
    public void init(Long playerId) {
        PlayerRank build = PlayerRank.builder()
                .uid(playerId)
                .build();
        build.insert();
        saveCache(build);
    }

    public void obtainExpReward(Long playerId, Long restValue) {
        PlayerRank playerRank = getById(playerId);
        playerRank.gainExperience(restValue);
        updateById(playerRank);
    }

    public void obtainIntegralReward(Long playerId, long resValue) {
        PlayerRank playerRank = getById(playerId);
        playerRank.gainRankIntegral(resValue);
    }
}
